package Q3;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int p = scanner.nextInt();

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        Arrays.sort(arr);

        long ret = 0;
        int k = 0;
        while (true) {
            int count = 0;
            for (int i = 0; i < n; i++) {
                if (Math.abs(arr[i] - k) <= p) {
                    count++;
                }
            }

            if (count > ret) {
                ret = count;
                k++;
            } else {
                break;
            }
        }

        System.out.println(ret);
    }
}
